package main

import (
	"fmt"
	"gitee.com/Cookie_XiaoD/godlock/zklock"
	"github.com/samuel/go-zookeeper/zk"
	"log"
	"time"
)

func main() {
	// 创建zk连接地址
	hosts := []string{"127.0.0.1:2181"}
	// 连接zk
	conn, _, err := zk.Connect(hosts, time.Second*60)

	if err != nil {
		return
	}
	defer conn.Close()

	lock, err := zklock.NewLock(conn, "/test")
	if err != nil {
		return
	}
	lock.LockBlock()
	defer lock.UnlockBlock()
	log.Println("业务逻辑....")
	_, _ = fmt.Scanln()
}
